package org.dubnation.base.excel.download.vo;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
import cn.afterturn.easypoi.excel.annotation.ExcelEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.dubnation.org.domain.Department;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Component
public class DepartmentVO implements Serializable {

    @Excel(name = "编号", width = 5, needMerge = true)
    private Long id;

    /**
     * 部门名称
     */
    @Excel(name = "部门名称", width = 20, needMerge = true)
    private String name;

    /**
     * 部门状态，0正常，1禁用
     */
    @Excel(name = "状态", width = 10, needMerge = true, replace = {"正常_0", "禁用_1"})
    private Integer state;

    /**
     * 上级部门
     */
    @Excel(name = "上级部门", width = 20, needMerge = true, replace = {"无_null"})
    private String parent;

    @Excel(name = "下级部门", width = 40, needMerge = true, replace = {"无_null"})
    private String children;

    /**
     * 部门员工
     */
    @ExcelEntity
    @ExcelCollection(name = "部门员工")
    private List<EmployeeVO> employeeVOS;

    /**
     * 部门管理的店铺
     */
    @ExcelEntity
    @ExcelCollection(name = "部门管理店铺")
    private List<ShopVO> shopVOS;

    /**
     * 将下级部门用、拼接成一个字符串
     * @param childList
     * @return
     */
    public static String getChildren(List<Department> childList) {
        StringBuilder builder = new StringBuilder();
        if (childList.size() > 0){
            childList.forEach(child ->
                    builder.append(child.getName()).append("、")
            );
            return builder.substring(0, builder.length() - 1);
        }else return null;
    }
}
